Skip to content

Conversation

@SannidhyaSah
Copy link
Collaborator

@SannidhyaSah SannidhyaSah commented Jun 29, 2025

Description

Closes #3967, #4524

This PR adds Google Gemini as a new embedding provider for codebase indexing, expanding the available options beyond OpenAI and Ollama. The implementation leverages Gemini's text-embedding-004 model through their OpenAI-compatible API endpoint.

Technical Architecture Decision

Why OpenAI-Compatible API Instead of Native Gemini Client?

We implemented GeminiEmbedder as a wrapper around OpenAICompatibleEmbedder rather than using the native Gemini/GenAI client due to significant performance limitations:

  • ~10x Performance Improvement: The native Gemini/Gen Ai client has inherent limitations that make embedding generation incredibly slow
  • Better Rate Limiting: OpenAI-compatible endpoint handles batching and rate limiting more efficiently
  • Improved User Experience: Prevents frustrating delays during codebase indexing
  • Proven Reliability: Leverages the battle-tested OpenAI-compatible infrastructure

This architectural choice prioritizes user experience while maintaining full compatibility with Gemini's powerful text-embedding-004 model.

Changes Made

Backend Implementation

  • New GeminiEmbedder class (src/services/code-index/embedders/gemini.ts) - Optimized wrapper around OpenAICompatibleEmbedder with Gemini-specific configuration:
    • Base URL: https://generativelanguage.googleapis.com/v1beta/openai/
    • Model: text-embedding-004
    • Dimension: 768
  • Updated service factory (src/services/code-index/service-factory.ts) - Added Gemini provider support
  • Updated config manager (src/services/code-index/config-manager.ts) - Added Gemini configuration handling
  • Updated type definitions (packages/types/src/global-settings.ts, packages/types/src/codebase-index.ts) - Added Gemini provider types

Frontend Implementation

  • Updated CodeIndexSettings component (webview-ui/src/components/settings/CodeIndexSettings.tsx) - Added Gemini to provider dropdown
  • Simplified configuration - Only requires API key input (base URL and model are pre-configured for optimal performance)

Internationalization

  • Complete i18n support - Added "Gemini" translations across all 18 supported languages:
    • Catalan, German, English, Spanish, French, Hindi, Indonesian, Italian, Japanese, Korean, Dutch, Polish, Portuguese (Brazil), Russian, Turkish, Vietnamese, Chinese (Simplified), Chinese (Traditional)

Testing

  • Comprehensive unit tests (src/services/code-index/embedders/__tests__/gemini.spec.ts) - Tests for GeminiEmbedder functionality
  • Updated existing tests - Modified service factory and config manager tests to include Gemini provider

Testing

  • All existing tests pass
  • Added comprehensive unit tests for GeminiEmbedder
  • Updated service factory and config manager tests
  • Manual testing completed:
    • Verified Gemini appears in provider dropdown
    • Confirmed API key input field works correctly
    • Tested provider switching functionality
    • Validated performance improvements over native client approach

Verification of Acceptance Criteria

Based on issue #4524 acceptance criteria:

  • Users can access Experimental section - Codebase indexing is in experimental settings
  • Users can enable Codebase indexing - Feature toggle works as expected
  • Users can select Gemini as Embedding Provider - Gemini now appears in dropdown
  • Simple configuration - Only API key required, model and endpoint are pre-configured for optimal performance

Related Issues

User Experience

Users can now:

  1. Navigate to Settings → Experimental → Codebase Indexing
  2. Select "Gemini" from the Embedding Provider dropdown
  3. Enter their Gemini API key
  4. Start indexing their codebase with Gemini's text-embedding-004 model

The implementation provides a seamless experience with automatic configuration of Gemini's optimal settings and significantly improved performance compared to the native client approach.

Performance Benefits

  • Fast Embedding Generation: ~10x faster than native Gemini client
  • Efficient Batching: Optimized request handling through OpenAI-compatible endpoint
  • Reduced Latency: Better rate limiting and connection management
  • Improved Reliability: Proven infrastructure for production workloads

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Comments added for complex logic
  • No breaking changes
  • All translations added for i18n support
  • Comprehensive test coverage
  • Follows existing embedding provider patterns
  • Performance optimizations implemented

Important

Adds Gemini embedding provider for codebase indexing using OpenAI-compatible API, with backend, frontend, i18n, and testing updates.

  • Behavior:
    • Adds GeminiEmbedder class in gemini.ts using OpenAI-compatible API for codebase indexing.
    • Supports text-embedding-004 model with fixed dimension 768.
    • Updates service-factory.ts and config-manager.ts to include Gemini provider.
  • Frontend:
    • Updates CodeIndexSettings.tsx to add Gemini to provider dropdown.
    • Simplifies configuration to require only API key input.
  • Internationalization:
    • Adds translations for "Gemini" in 18 languages.
  • Testing:
    • Adds unit tests in gemini.spec.ts.
    • Updates tests in config-manager.spec.ts and service-factory.spec.ts for Gemini support.

This description was created by Ellipsis for dfc844e. You can customize this summary. It will automatically update as commits are pushed.

SannidhyaSah and others added 4 commits June 28, 2025 18:51
- Changed VSCodeTextField to use placeholder instead of default value
- Users can now clear the field without it auto-filling
- Maintains backward compatibility with existing configurations
- All existing tests continue to pass
@SannidhyaSah SannidhyaSah requested review from cte, jr and mrubens as code owners June 29, 2025 06:45
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jun 29, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 29, 2025
@shariqriazz
Copy link
Contributor

You might wanna adjust MAX_TOKENS_PER_TEXT: 2048 for this model

- Fix inconsistent logic in CodeIndexSettings where Gemini was incorrectly included in OpenAI model fallback
- Add clarifying comment for hardcoded Gemini embedding dimension (768) in service-factory
…splay

- Add GEMINI_MAX_ITEM_TOKENS constant (2048) for text-embedding-004 model
- Update OpenAICompatibleEmbedder to accept configurable maxItemTokens
- Pass token limit from GeminiEmbedder to OpenAICompatibleEmbedder
- Fix UI to properly display Gemini model in dropdown
- Update tests to handle new maxItemTokens parameter
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 29, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jun 29, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @SannidhyaSah

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 1, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Jul 1, 2025
@mrubens mrubens merged commit 87aa688 into RooCodeInc:main Jul 3, 2025
20 checks passed
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jul 3, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 3, 2025
@SannidhyaSah SannidhyaSah deleted the geminiembedding-provider branch July 12, 2025 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer PR - Needs Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Enhancement of Gemini Integration in Roo Code Codebase Indexing: Add Google Gemini as provider

5 participants